/*
   @Copyright:LibreOJ
   @Author:   tjyemail
   @Problem:  https://loj.ac/problem/109
   @Language: C++
   @Datetime: 20-08-03 15:07
   */
// fread; time 513ms
#include <bits/stdc++.h>
using namespace std;
#include <sys/mman.h>

#define MOD 998244353
int roots[4000004];
inline int find(int leaf) {
	return leaf==roots[leaf] ? leaf : roots[leaf]=find(roots[leaf]);
}

typedef int _FR_TYPE;
char _FR_BUF[102400];
struct _FR {
	char *buf;
	size_t size, block, idx, end;
	_FR_TYPE num;
	_FR(char *_buf, size_t _size, size_t _block):buf(_buf), size(_size), block(_block){idx=end=size;}
	inline _FR_TYPE read() {
		if (idx > size - block && end == size) {
			memmove(buf, buf + idx, end - idx);
			end = size - idx + fread(buf + size - idx, 1, idx, stdin);
			idx = 0;
		}
		for (num=0; !isdigit(buf[idx]); ++idx);
		for (; isdigit(buf[idx]); ++idx)
			num = num * 10LL + buf[idx] - '0';
		return num;
	}
} fr(_FR_BUF, sizeof(_FR_BUF), 16);

int main() {
	long long ans = 0;
	int v=fr.read(), e=fr.read(), o, a, b;
	for(int i=0; i++<v; roots[i]=i);
	for(; e--; ) {
		o = fr.read(), a = fr.read(), b = fr.read();
		a = find(a), b = find(b);
		if (!o) roots[a] = b;
		else {
			ans = (ans<<1) | a==b;
			ans = ans > MOD ? ans-MOD : ans;
		}
	}
	printf("%lld\n", ans%MOD);
	return 0;
}
